-
Notifications
You must be signed in to change notification settings - Fork 41k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document all the available Testcontainers integrations #44187
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This clarification is great! I've left some comments that could help.
...project/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/testcontainers.adoc
Outdated
Show resolved
Hide resolved
...project/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/testcontainers.adoc
Outdated
Show resolved
Hide resolved
== Using via Spring managed beans | ||
|
||
The containers provided by Testcontainers framework can be managed by Spring Boot as beans. | ||
This method is often used in combination with javadoc:org.springframework.boot.testcontainers.service.connection.ServiceConnection[format=annotation]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ServiceConnection
can be used with static fields and beans.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not quite understand what you mean with that, in context of the code which is selected here in comment. Is it that the sentence "This method is often used in combination with..." seems to point that it is the only combination in which @ServiceConnection
annotation is used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I rephrased the sentence so that it is clearer that this is not the only option. I hope now it is satisfactory. If not feel free to continue the discussion.
...project/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/testcontainers.adoc
Show resolved
Hide resolved
|
||
== Using via importing container declaration classes | ||
|
||
A common pattern with Testcontainers framework is to declare the Container instances as static fields in an interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, it should highlight that this enables reusability of container configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do that. I partially disagree though. As I am reading through rest of the Spring documentation I note that it is focused solely on documenting on which features are offered by Spring, and does not repeat or clarify software development "best practices". I followed this style here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added as tip
== Lifecycle of managed containers | ||
|
||
If you have used the annotations and extensions provided by Testcontainers framework, then the lifecycle of container instances is managed by the Testcontainers framework. | ||
Please refer to the official documentation for the information about lifecycle of the containers, when managed by the Testcontainers framework. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add Link to the official docs maybe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Antora offer broken link checks? If so I will gladly add the link. I was cautious about inclusion of links, because links change and that can be irritating for the readers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added as Antora attribute.
|
||
The test containers can be started multiple times. | ||
Like any other beans the test containers are created and started once per application context managed by the TestContext Framework. | ||
For details about how TestContext framework manages the underlying application contexts and beans therein, please refer to the official Spring documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should add link?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that here you are refering to link to TestContext Framework
docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added reference to Spring docs, without deep linking to TestContext framework.
The container beans are stopped after the destruction of beans of other types. | ||
This ensures that any beans depending on the functionalities provided by the containers are cleaned up first. | ||
|
||
The containers are stopped as part of the application shutdown process, managed by the TestContext framework. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is important to highlight. In some cases, for example, using activemq, kafka, pulsar and other containers, I recommend to declare it as a beans rather than static fields because that way the application context will shutdown the client first and then the container. Otherwise, when the container shutdown first the client will throw some errors because connection has been lost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that you would like to have a concrete example in addition to the general explanation already provided, so that the readers can more clearly understand the "why" behind usage. Is my understanding correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added as tips and notes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tips and notes are great! my examples were only to provide an explanation about the issue en general. 👍🏽
38c227f
to
bd96459
Compare
@eddumelendez Ready for re-review. |
8398340
to
092e4ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left additional comments. LGTM, in general. Thanks again!
== Using via @Testcontainers JUnit5 extension | ||
|
||
The Testcontainers provides JUnit5 extensions, which can be used to manage containers in your tests. | ||
The extension is activated by applying the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incomplete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wierd that I missed that, given that I know exactly what my thoughts were here. I will fill this up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so I corrected this and completerd the sentence.
...project/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/testcontainers.adoc
Show resolved
Hide resolved
The container beans are stopped after the destruction of beans of other types. | ||
This ensures that any beans depending on the functionalities provided by the containers are cleaned up first. | ||
|
||
The containers are stopped as part of the application shutdown process, managed by the TestContext framework. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tips and notes are great! my examples were only to provide an explanation about the issue en general. 👍🏽
In this commit I have documented three methods of starting containers from Testcontainer library as part of the Spring Boot tests. Signed-off-by: Vanio Begic <[email protected]>
Signed-off-by: Vanio Begic <[email protected]>
Closes spring-projects#43738 Signed-off-by: Vanio Begic <[email protected]>
Signed-off-by: Vanio Begic <[email protected]>
Signed-off-by: Vanio Begic <[email protected]>
Concretely I have ensured that there are three lines between text and next header. Also I added anchors to each header Signed-off-by: Vanio Begic <[email protected]>
Signed-off-by: Vanio Begic <[email protected]>
0d6ff97
to
92efef4
Compare
@eddumelendez I think we should be good to go now 🤞 |
The test containers can be started multiple times. | ||
Like any other beans the test containers are created and started once per application context managed by the TestContext Framework. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be just containers instead of test containers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! thanks!
In this PR I have documented the ways in which containers provided by Testcontainers framework can be incorporated into the test tests managed by Spring's TestContext Framework.
In addition to describing how to use the containers, information on lifecycle of containers during tests has been added.